package com.pyb.common.sms.biz.service.enums;

import org.apache.commons.lang3.StringUtils;

/**
 * SmsTemplete
 *
 * @author chuchen.zhang
 * @date 17-2-27 下午10:49
 */
public enum SmsTemplete {

	SECURITY_TEMPLETE("{1}为您的登录验证码，请于{2}分钟内填写。如非本人操作，请忽略本短信。", 11505)

	;

	private static final String TEMPLETE_KEYWORD_PATTERN = "\\{\\p{Digit}+\\}";

	private String originalTemplete;

	private String formatTemplete;

	private int templeteId;

	SmsTemplete(String originalTemplete, int templeteId) {
		this.originalTemplete = originalTemplete;
		this.templeteId = templeteId;
		this.formatTemplete = convert(originalTemplete);
	}

	private String convert(String originalTemplete) {
		return StringUtils.replacePattern(originalTemplete, TEMPLETE_KEYWORD_PATTERN, "%s");
	}

	public String getFormatTemplete() {
		return formatTemplete;
	}

	public void setFormatTemplete(String formatTemplete) {
		this.formatTemplete = formatTemplete;
	}

	public String getOriginalTemplete() {
		return originalTemplete;
	}

	public void setOriginalTemplete(String originalTemplete) {
		this.originalTemplete = originalTemplete;
	}

	public int getTempleteId() {
		return templeteId;
	}

	public void setTempleteId(int templeteId) {
		this.templeteId = templeteId;
	}

	public String fillContent(String... keywords) {
		return String.format(formatTemplete, keywords);
	}
}
